<?php include $this->getViewFile('/common/Head') ?>
<body class="J_scroll_fixed">
<style>
.col-left{float:left}
.col-auto{overflow:hidden;_zoom:1;_float:left;}
.title-1{border-bottom:1px solid #eee; padding-left:5px}
.f14{font-size: 14px}
.lh28{line-height: 28px}
.blue,.blue a{color:#004499}
.gray4,a.gray4{color:#999;}
.lh22{line-height: 22px}
.lh25{line-height: 25px}
</style>
<div class="wrap J_check_wrap">
  <?php include $this->getViewFile('/common/Nav') ?>
  <div class="h_a">查找</div>
  <form method="post" action="" id="searchForm">
    <div class="search_type cc mb10">
      <div class="mb10"> 
      状态：<?php echo Form::select(array(1=>'正常',0=>'待审核',),$status,'name="status"','全部') ?>
        开始时间：
        <input type="text" name="start_time" class="input length_2 J_date" value="<?php echo $start_time?>" placeholder="选择起始时间">
        -
        <input type="text" class="input length_2 J_date" name="end_time" value="<?php echo $end_time?>" placeholder="选择结束时间">
       </div>
       <div class="mb10">
        关键字：<?php echo Form::select(array(1=>'商品标题',),$type,'name="type"') ?>
        <input type="text" class="input length_2" name="keyword" style="width:200px;" value="<?php echo $keyword?>" placeholder="请输入搜索内容...">
        <button class="btn">搜索</button>
      </div>
    </div>
  </form>
  <div class="mb10"> 共有 ( <b><?php echo $count; ?></b> ) 个宝贝</div>
  <form name="myform" action="" method="post" class="J_ajaxForm">
    <div class="table_list">
      <table width="100%" cellspacing="0">
        <thead>
          <tr>
            <td width="50" align="center"><input type="checkbox" class="J_check_all" data-direction="x" data-checklist="J_check_x">全选</td>
            <td align="center">兑换商品信息</td>
            <td width="100" align="center">状态</td>
            <td width="200" align="center">管理操作</td>
          </tr>
        </thead>
        <tbody>
         <?php
		 foreach($data as $rs){
		 ?>
         <tr  id="gbinfo_<?php echo $rs->id;?>">
            <?php include $this->getViewFile('public_load'); ?>
         </tr>
         <?php
		 }
		 ?>
        </tbody>
      </table>
      <div class="p10">
        <div class="pages"><?php echo $Page;?></div>
      </div>
    </div>
  </form>
</div>
<script src="<?php echo $staticUrl; ?>statics/js/common.js"></script>
<script>
//加载信息
function loads(id){
	$.get('<?php echo AdminBase::U("public_load") ?>',{id:id},function(data){
		if(data != ''){
			$("#gbinfo_"+id).html(data);
			changes();
		}
	});
}
//保存
function saveData(data){
	Wind.use("artDialog", "iframeTools", function () {
		$.post('<?php echo AdminBase::U("edit") ?>',data,function(rs){
			if(rs.status){
				art.dialog.tips('修改成功！', 1.5);
			}else{
				art.dialog.tips(rs.info, 3);
			}
			//重新加载
			loads(data.id);
		},'json');
	});
}
//绑定修改事件
function changes(){
	//标题修改
	$('input[name="title"]').change(function(){
		var id = $(this).data('id');
		var title = $(this).val();
		if(title != '' && id > 0){
			var data = {id:id,title:title};
			saveData(data);
			return true;
		}
		return false;
	});
	//兑换积分
	$('input[name="integral"]').change(function(){
		var id = $(this).data('id');
		var integral = $(this).val();
		if(integral != '' && id > 0){
			var data = {id:id,integral:integral};
			saveData(data);
			return true;
		}
		return false;
	});
	//限量
	$('input[name="quantum"]').change(function(){
		var id = $(this).data('id');
		var quantum = $(this).val();
		if(quantum != '' && id > 0){
			var data = {id:id,quantum:quantum};
			saveData(data);
			return true;
		}
		return false;
	});
	//兑换次数
	$('input[name="frequency"]').change(function(){
		var id = $(this).data('id');
		var frequency = $(this).val();
		if(frequency != '' && id > 0){
			var data = {id:id,frequency:frequency};
			saveData(data);
			return true;
		}
		return false;
	});
	//会员组
	$('input[name="member_group[]"]').change(function(){
		var id = $(this).data('id');
		var value=''
		var l = $(this).parent().find('input[name="member_group[]"]:checked').length;
		$.each($(this).parent().find('input[name="member_group[]"]:checked'), function(i,o) {
			if(i < l-1){
				value += $(this).attr('value') + ',';
			}else{
				value += $(this).attr('value');
			}
		});
		var data = {id:id,member_group:value};
		saveData(data);
		return true;
	});
	//开始时间
	$('input[name="start_time"]').change(function(){
		var id = $(this).data('id');
		var start_time = $(this).val();
		if(start_time != '' && id > 0){
			var data = {id:id,start_time:start_time};
			saveData(data);
			return true;
		}
		return false;
	});
	//结束时间
	$('input[name="end_time"]').change(function(){
		var id = $(this).data('id');
		var end_time = $(this).val();
		if(end_time != '' && id > 0){
			var data = {id:id,end_time:end_time};
			saveData(data);
			return true;
		}
		return false;
	});
	//状态
	$('select[name="status"]').change(function(){
		var id = $(this).data('id');
		var status = $(this).val();
		if(id > 0){
			var data = {id:id,status:status};
			saveData(data);
			return true;
		}
		return false;
	});
}

$(function(){
	changes();
});
</script>
</body>
</html>